var http=require('http');
var express = require('express');
var router = express.Router();
var exclude = require('./login_exclude_list');
var schedule = require('../../services/service.schedule.js');
// var globalschedule = require('../../services/service.globalschedule.js');
var evaluateService = require('../../services/service.evaluate.js');
var contactService=require('../../services/service.contact.js');
var recommendService =require('../../services/service.recommend.js');
var otherService =require('../../services/service.other.js');
var userService =require('../../services/service.user.js');
var homeService =require('../../services/service.home.js');
var morningconferenceService = require('../../services/service.mconference.js');
var stockrecommend = require('../../services/service.stockrecommend.js');
var seller = require('../../services/service.seller.js');
var stockpool = require('../../services/service.stockpool.js');
var knowledgeGroupServer = require('../../services/service.knowledgeGroup.js');

var addressbookService = require('../../services/service.addressbook.js');
var knowledgeCenter = require('../../services/service.knowledgecenter.js');
var stockUtil = require('../../utils/stock');
var searchService =require('../../services/service.search');

var stockChannelService = require('../../services/service.stockChannel');
var stockGroupService = require('../../services/service.stockGroup');
var stockDealService = require('../../services/service.stockDeal');

//鉴权session中的uid
router.use(function(req,res,next) {
    exclude.contains(req.originalUrl) ? next() :
        homeService.checkSession(req,res,function (result) {
            req.session.relogin = !!req.headers.referer;
            result.uid ? next() : res.redirect('/smtool_project/wxapp/login');
    });
});

//主路由
router.post('/', function(req, res, next) {
    res.render('app/home/home.ejs',{'session':req.session});
});

//主路由
router.get('/', function(req, res, next) {
    res.render('app/home/home.ejs',{'session':req.session});
});

////20170625 注释teamid相关行为，直接放行到home
// //team选择
// router.get('/teamselect', function(req, res, next) {
//     homeService.checkTeam(req,res,function (result) {
//         res.render('app/login/teamselect.ejs',result);
//     })
// });
//
// //team选择
// router.post('/teamselect', function(req, res, next) {
//     homeService.checkTeam(req,res,function (result) {
//         res.render('app/login/teamselect.ejs',result);
//     })
// });


//获取实时价格API
router.get('/api/stock/getRealPrice', function (req, res, next) {
    stockUtil.getRealtimePrice((req.query || {}).stockCode,function (err,result) {
         res.send(err || result || '');
    });
});


//统计
//统计-首页
// router.get('/statistics/index', function(req, res, next) {
//     seller.getSellerList(req, res, function(result) {
//         res.render('app/statistics/index.ejs',result);
//     })
// });
//统计
router.get('/statistics/statisticsCount', function(req, res, next) {
        res.render('app/statistics/newIndex.ejs',null);
});
//统计-晨会
router.get('/statistics/getMorningconferenceCount', function(req, res, next) {
    morningconferenceService.getMorningconferenceCount(req, res, function(result) {
        res.send(result);
    })
});
//统计-晨会-前十行业
router.get('/statistics/getTopIndustry', function(req, res, next) {
    morningconferenceService.getTopIndustry(req, res, function(result) {
        res.send(result);
    })
});
//统计-晨会-前十公司
router.get('/statistics/getTopCompany', function(req, res, next) {
    morningconferenceService.getTopCompany(req, res, function(result) {
        res.send(result);
    })
});
//统计-金股/股票池
router.get('/statistics/getStockCount', function(req, res, next) {
    stockrecommend.getStockCount(req, res, function(result) {
        res.send(result);
    })
});

//统计-详情
router.get('/statistics/detail', function(req, res, next) {
    evaluateService.getEvaluateInfoList(req, res, function(result) {
        res.render('app/statistics/detail.ejs',result);
    })
});

//晨会
//晨会-首页
router.get('/morningconference/index', function(req, res, next) {
    //morningconferenceService.getMorningconferenceServicetList(req, res, function(result) {
        res.render('app/morningconference/morningconferenceindex.ejs',null);
    //})
});
//晨会-评论
router.get('/morningconference/addComment', function(req, res, next) {
        res.render('app/morningconference/addComment.ejs',null);
}).post('/morningconference/addComment', function(req, res, next) {
    morningconferenceService.addComment(req, res, function(result) {
        res.send(result);
    })
});
//评论-修改
router.post('/morningconference/updateComment', function(req, res, next) {
    morningconferenceService.updateComment(req, res, function(result) {
        res.send(result);
    })
});
//评论-删除
router.post('/morningconference/delComment', function(req, res, next) {
    morningconferenceService.delComment(req, res, function(result) {
        res.send(result);
    })
});
//晨会-新建晨会
router.get('/morningconference/add', function(req, res, next) {
    morningconferenceService.initMorningconference(req, res, function (result) {
        res.render('app/morningconference/morningconferenceadd.ejs',result);
    })
}).post('/morningconference/add', function(req, res, next) {
    morningconferenceService.editMConference(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/morningconference/index');
    });
});

//晨会-晨会详情
router.get('/morningconference/morningconferencedetail', function(req, res, next) {
    morningconferenceService.getMConferenceInfo(req, res, function(result) {
        if(req.query.page == 'search')
            result.page = 'search';
        res.render('app/morningconference/morningconferencedetail.ejs',result);
    })
});
//晨会-删除
router.post('/morningconference/delMConference', function(req, res, next) {
    morningconferenceService.delMConference(req, res, function (result) {
        res.send(result);
        //res.redirect('/smtool_project/wxapp/morningconference/index');
    });
});
//晨会-审批
router.post('/morningconference/approval', function(req, res, next) {
    morningconferenceService.approveMConference(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/morningconference/index');
    });
});
/**
 * 按照seller查询用户
 */
router.get('/api/user/getUserListBySeller', function (req, res, next) {
    userService.getUserListBySeller(req, res,function (result) {
        res.send(result.list);
    });
});

//股票池
//股票池-股票池首页
router.get('/stockpool/stockpoolindex', function(req, res, next) {
    req.body.parentId = '0';
    stockpool.getStockRecommendListWithGroup(req, res, function(result) {
        result.personal = !!req.query.createUid;
        res.render('app/stockpool/index.ejs',result);
    });
});

router.get('/stockpool/:type/export.xlsx', function(req, res, next) {
    var createUid = req.params.type=='personal'?req.session.uid:null;
    if (createUid)
        req.query.createUid = createUid;
    stockpool.exportStockPoolAsExcel(req, res, function(result) {

    });
});

//股票池-股票池首页-普通列表
router.post('/stockpool/stockpoolindex/list', function (req, res, next) {
    stockpool.getStockRecommendList(req, res, function(result) {
        res.send(result);
    });
});

//股票池-股票池首页-分组树形列表
router.post('/stockpool/stockpoolindex/tree', function (req, res, next) {
    stockpool.getStockRecommendListWithGroup(req, res, function(result) {
        res.send(result);
    });
});

//股票池-新建股票池
router.get('/stockpool/edit', function(req, res, next) {
    stockpool.initStockRecommend(req, res, function(result) {
        res.render('app/stockpool/stockpooledit.ejs',result);
    })
}).post('/stockpool/save', function(req, res, next) {
    stockpool.createOrUpdateStockPool(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/stockpool/stockpoolindex');
    });
});

//股票池-新建-校验股票是否已在池中
router.get('/stockpool/stock/:stockCode', function(req, res, next) {
    stockpool.isStockExistInPool(req, res, function(result) {
        res.send(result);
    });
});

//股票池-查看股票池
router.get('/stockpool/stockpooldetail', function(req, res, next) {
    stockpool.getStockRecommendInfo(req, res, function(result) {
        if(req.query.page == 'search')
            result.page = 'search';
        res.render('app/stockpool/stockpooldetail.ejs',result);
    })
});

//股票池-删除股票池推荐
router.post('/stockpool/stockpooldelete', function(req, res, next) {
    stockpool.delteStockRecommendList(req, res, function(result) {
        res.send(result);
    })
});

//股票池-新建股票池层级目录
router.get('/stockpoolgroup',function (req, res, next) {
    res.render('app/stockpool/stockpoolgroup.ejs');
});

//新建股票池分组
router.post('/stockpool/createstockpoolgroup', function (req, res, next) {
    req.body.createUid = req.session.uid;
    stockpool.createStockPoolGroup(req,res,function (result) {
        res.send(result);
    });
});

//修改股票池分组名称
router.post('/stockpool/updateStockPoolGroup', function (req, res, next) {
    stockpool.updateStockPoolGroup(req,res,function (result) {
        res.send(result);
    });
});

//查询股票池分组列表
router.post('/stockpool/listStockPoolGroup', function (req, res, next) {
    stockpool.listStockPoolGroup(req,res,function (result) {
        res.send(result);
    });
});
//知识库-新建子栏目目录
router.get('/knowledge/group',function (req, res, next) {
    res.render('app/knowledge/group.ejs');
});

//知识库-新建子栏目
router.post('/knowledge/createKnowledgeGroup', function (req, res, next) {
    req.body.createUid = req.session.uid;
    knowledgeGroupServer.createKnowledgeGroup(req,res,function (result) {
        res.send(result);
    });
});

//知识库-修改子栏目
router.post('/knowledge/updateKnowledgeGroup', function (req, res, next) {
    knowledgeGroupServer.updateKnowledgeGroup(req,res,function (result) {
        res.send(result);
    });
});

//知识库-查询子栏目列表
router.post('/knowledge/listKnowledgeGroup', function (req, res, next) {
    knowledgeGroupServer.listKnowledgeGroup(req,res,function (result) {
        res.send(result);
    });
});

//我的日历
router.get('/globalschedule/index', function(req, res, next) {
    schedule.index(req, res, function(result) {
        res.render('app/globalschedule/schedule.ejs', result);
    })
});

//获取我的日历列表API
router.get('/api/globalschedule/list', function (req, res, next) {
    schedule.list(req, res, function (result) {
        res.set('Content-Type', 'application/json');
        res.send(result);
    })
});

//我的日历 -- 调研详情
router.get('/globalschedule/survey/detail', function(req, res, next) {
    schedule.surveyDetail(req, res, function (result) {
        res.render('app/globalschedule/surveydetail.ejs', result);
    });
});

//我的日历 -- 参加调研
router.post('/globalschedule/survey/join', function(req, res, next) {
    schedule.surveyJoin(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/globalschedule/index');
    });
});

//我的日历 -- 退出参加调研
router.post('/globalschedule/survey/exit', function(req, res, next) {
    schedule.surveyExit(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/globalschedule/index');
    });
});


//我的日历 -- 路演详情
router.get('/globalschedule/roadshow/detail', function(req, res, next) {
    schedule.roadshowDetail(req, res, function (result) {
        res.render('app/globalschedule/roadshowdetail.ejs', result);
    });
});


//我的日历 -- 参加路演
router.post('/globalschedule/roadshow/join', function(req, res, next) {
    schedule.roadshowJoin(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/globalschedule/index');
    });
});

//我的日历 -- 退出参加路演
router.post('/globalschedule/roadshow/exit', function(req, res, next) {
    schedule.roadshowExit(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/globalschedule/index');
    });
});


//我的日历 -- 策略会详情
router.get('/globalschedule/strategy/detail', function(req, res, next) {
    schedule.strategyDetail(req, res, function (result) {
        res.render('app/globalschedule/strategydetail.ejs', result);
    });
});

//我的日历 -- 参加策略会
router.post('/globalschedule/strategy/join', function(req, res, next) {
    schedule.strategyJoin(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/globalschedule/index');
    });
});

//我的日历 -- 退出参加策略会
router.post('/globalschedule/strategy/exit', function(req, res, next) {
    schedule.strategyExit(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/globalschedule/index');
    });
});



//我的日历 -- 电话会议详情
router.get('/globalschedule/teleconference/detail', function(req, res, next) {
    schedule.teleconferenceDetail(req, res, function (result) {
        res.render('app/globalschedule/teleconferencedetail.ejs', result);
    });
});

//我的日历 -- 参加电话会议
router.post('/globalschedule/teleconference/join', function(req, res, next) {
    schedule.teleconferenceJoin(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/globalschedule/index');
    });
});

//我的日历-- 退出参加电话会议
router.post('/globalschedule/teleconference/exit', function(req, res, next) {
    schedule.teleconferenceExit(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/globalschedule/index');
    });
});





//路演调研
router.get('/schedule/index', function(req, res, next) {
    schedule.index(req, res, function(result) {
        res.render('app/schedule/schedule.ejs', result);
    })
});

//获取我的日程列表API
router.get('/api/schedule/list', function (req, res, next) {
    schedule.list(req, res, function (result) {
        res.set('Content-Type', 'application/json');
        res.send(result);
    })
});

//路演调研 -- 添加调研
router.get('/schedule/survey/add', function(req, res, next) {
    schedule.initCreateSurvey(req, res, function (result) {
        res.render('app/schedule/surveyadd.ejs', result);
    })
}).post('/schedule/survey/add', function(req, res, next) {
    schedule.createSurvey(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 修改调研
router.get('/schedule/survey/edit', function(req, res, next) {
    schedule.initEditSurvey(req, res, function (result) {
        res.render('app/schedule/surveyedit.ejs', result);
    })
}).post('/schedule/survey/edit', function(req, res, next) {
    schedule.editSurvey(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 删除调研
router.post('/schedule/survey/delete', function(req, res, next) {
    schedule.surveyDelete(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 调研详情
router.get('/schedule/survey/detail', function(req, res, next) {
    schedule.surveyDetail(req, res, function (result) {
        res.render('app/schedule/surveydetail.ejs', result);
    });
});

//路演调研 -- 参加调研
router.post('/schedule/survey/join', function(req, res, next) {
    schedule.surveyJoin(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 退出参加调研
router.post('/schedule/survey/exit', function(req, res, next) {
    schedule.surveyExit(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 添加路演
router.get('/schedule/roadshow/add', function(req, res, next) {
    schedule.initCreateRoadshow(req, res, function (result) {
        res.render('app/schedule/roadshowadd.ejs', result);
    })
}).post('/schedule/roadshow/add', function(req, res, next) {
    schedule.createRoadshow(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 修改路演
router.get('/schedule/roadshow/edit', function(req, res, next) {
    schedule.initEditRoadshow(req, res, function (result) {
        res.render('app/schedule/roadshowedit.ejs', result);
    })
}).post('/schedule/roadshow/edit', function(req, res, next) {
    schedule.editRoadshow(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 删除路演
router.post('/schedule/roadshow/delete', function(req, res, next) {
    schedule.roadshowDelete(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 路演详情
router.get('/schedule/roadshow/detail', function(req, res, next) {
    schedule.roadshowDetail(req, res, function (result) {
        res.render('app/schedule/roadshowdetail.ejs', result);
    });
});

//路演调研 -- 参加路演
router.post('/schedule/roadshow/join', function(req, res, next) {
    schedule.roadshowJoin(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 退出参加路演
router.post('/schedule/roadshow/exit', function(req, res, next) {
    schedule.roadshowExit(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 添加策略会
router.get('/schedule/strategy/add', function(req, res, next) {
    schedule.initCreateStrategy(req, res, function (result) {
        res.render('app/schedule/strategyadd.ejs', result);
    })
}).post('/schedule/strategy/add', function(req, res, next) {
    schedule.createStrategy(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 修改策略会
router.get('/schedule/strategy/edit', function(req, res, next) {
    schedule.initEditStrategy(req, res, function (result) {
        res.render('app/schedule/strategyedit.ejs', result);
    })
}).post('/schedule/strategy/edit', function(req, res, next) {
    schedule.editStrategy(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 删除策略会
router.post('/schedule/strategy/delete', function(req, res, next) {
    schedule.strategyDelete(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 策略会详情
router.get('/schedule/strategy/detail', function(req, res, next) {
    schedule.strategyDetail(req, res, function (result) {
        res.render('app/schedule/strategydetail.ejs', result);
    });
});

//路演调研 -- 参加策略会
router.post('/schedule/strategy/join', function(req, res, next) {
    schedule.strategyJoin(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 退出参加策略会
router.post('/schedule/strategy/exit', function(req, res, next) {
    schedule.strategyExit(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 添加电话会议
router.get('/schedule/teleconference/add', function(req, res, next) {
    schedule.initCreateTeleconference(req, res, function (result) {
        res.render('app/schedule/teleconferenceadd.ejs', result);
    })
}).post('/schedule/teleconference/add', function(req, res, next) {
    schedule.createTeleconference(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 修改电话会议
router.get('/schedule/teleconference/edit', function(req, res, next) {
    schedule.initEditTeleconference(req, res, function (result) {
        res.render('app/schedule/teleconferenceedit.ejs', result);
    })
}).post('/schedule/teleconference/edit', function(req, res, next) {
    schedule.editTeleconference(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 删除电话会议
router.post('/schedule/teleconference/delete', function(req, res, next) {
    schedule.teleconferenceDelete(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研 -- 电话会议详情
router.get('/schedule/teleconference/detail', function(req, res, next) {
    schedule.teleconferenceDetail(req, res, function (result) {
        res.render('app/schedule/teleconferencedetail.ejs', result);
    });
});

//路演调研 -- 参加电话会议
router.post('/schedule/teleconference/join', function(req, res, next) {
    schedule.teleconferenceJoin(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研-- 退出参加电话会议
router.post('/schedule/teleconference/exit', function(req, res, next) {
    schedule.teleconferenceExit(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//路演调研-- 添加其他
router.get('/schedule/workdiary/page', function(req, res, next) {
    schedule.initWorkDiary(req, res, function (result) {
        res.render('app/schedule/workdiaryadd.ejs',result);
    });
}).post('/schedule/workdiary/add', function(req, res, next) {
    schedule.createWorkDiary(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
}).post('/schedule/workdiary/edit', function(req, res, next) {
    schedule.updateWorkDiary(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
}).post('/schedule/workdiary/delete', function(req, res, next) {
    schedule.deleteWorkDiary(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/schedule/index');
    });
});

//通讯录
router.get('/addressbook/index', function(req, res, next) {
    res.render('app/addressbook/index.ejs',null);

}).post('/addressbook/index', function(req, res, next) {
    addressbookService.getAddressbookList(req, res, function(result) {
        res.send(result);
    })
});
//通讯录 -- 详情
router.get('/addressbook/detail', function(req, res, next) {
    addressbookService.getDetail(req, res, function(result) {
        res.render('app/addressbook/detail.ejs',result);
    });
});
//通讯录 -- 添加联系人
router.post('/addressbook/add', function(req, res, next) {
    addressbookService.editAddressbook(req, res, function(result) {
        res.send(result);
    });
    //userService.addUser(req, res, function(result) {
    //    res.send(result);
    //});
});
//通讯录 -- 修改联系人
router.post('/addressbook/edit', function(req, res, next) {
    addressbookService.editAddressbook(req, res, function(result) {
        res.send(result);
    });
});
//通讯录 -- 删除联系人
router.post('/addressbook/del', function(req, res, next) {
    addressbookService.del(req, res, function(result) {
        res.send(result);
    });
});
//通讯录 -- 获取公司联想
router.get('/addressbook/companySearch', function(req, res, next) {
    addressbookService.companySearch(req, res, function(result) {
        res.send(result);
    });
});
//通讯录 -- 获取角色联想
router.get('/addressbook/deptSearch', function(req, res, next) {
    addressbookService.deptSearch(req, res, function(result) {
        res.send(result);
    });
});
//行业分组
//行业分组-首页
router.get('/stockgroup/index', function(req, res, next) {
    res.render('app/stockgroup/index.ejs',null);
}).post('/stockgroup/index', function(req, res, next) {
    stockGroupService.getList(req, res, function(result) {
        res.send(result);
    })
});
router.get('/stockgroup/edit', function(req, res, next) {
    res.render('app/stockgroup/edit.ejs',null);
})
router.get('/stockgroup/addChannels', function(req, res, next) {
    stockGroupService.addChannels(req, res, function(result) {
        res.send(result);
    })
})
//行业分组-详情
router.get('/stockgroup/detail', function(req, res, next) {
    res.render('app/stockgroup/detail.ejs',{groupId:req.query.groupId});
}).post('/stockgroup/detail', function(req, res, next) {
    stockGroupService.getByGroupId(req, res, function(result) {
        res.send(result);
    })
});
//行业分组-持仓详情
router.post('/stockgroup/stockList', function(req, res, next) {
    stockGroupService.getStockList(req, res, function(err,result) {
        res.send(result);
    })
});
//股票交易
//股票交易-编辑
router.get('/stockdeal/edit', function(req, res, next) {
    res.render('app/stockdeal/edit.ejs',{type:req.query.type,groupId:req.query.groupId});
});
router.post('/stockdeal/createOrUpdate', function(req, res, next) {
    stockDealService.createOrUpdate(req, res, function(result) {
        res.send(result);
    })
});
router.post('/stockdeal/dealList', function(req, res, next) {
    stockDealService.getList(req, res, function(result) {
        res.send(result);
    })
});
//股票信息
//股票信息-修改
router.post('/stockChannel/update', function(req, res, next) {
    stockChannelService.update(req, res, function(result) {
        res.send(result);
    });

});
//成员管理
router.get('/accountmgr/index', function(req, res, next) {
    //res.render('app/accountmgr/index.ejs');
    userService.getuserList(req, res, function(result) {
        res.render('app/accountmgr/index.ejs',result);
    })
});
//成员管理 --- 成员详情
router.get('/accountmgr/detail', function(req, res, next) {
    //res.render('app/accountmgr/detail.ejs');
    userService.showDetail(req, res, function(result) {
        res.render('app/accountmgr/detail.ejs',result);
    })

});
//成员管理 --- 添加成员
router.post('/accountmgr/addUser', function(req, res, next) {
    userService.addUser(req, res, function(result) {
        res.send(result);
    });
});

//成员管理 --- 删除成员
router.post('/accountmgr/delUser', function(req, res, next) {
    userService.delUser(req, res, function(result) {
        res.send(result);
    });
    //res.render('app/accountmgr/detail.ejs');
});
//成员管理 --- 修改成员
router.post('/accountmgr/editUser', function(req, res, next) {
    userService.editUser(req, res, function(result) {
        res.send(result);
    });
    //res.render('app/accountmgr/detail.ejs');
});


//评价 -- 1.主页
router.get('/evaluate/index', function(req, res, next) {

    evaluateService.getEvaluateSellerList(req, res, function(result) {
        //res.render('app/schedule/index.ejs', result);
        res.render('app/evaluate/evaluate.ejs',result);
    })

});

//评价 -- 2.服务列表
router.get('/evaluate/servicelist', function(req, res, next) {

    evaluateService.getEvaluateServiceList(req, res, function(result) {
        // res.render('app/evaluate/servicelist.ejs',result);
        res.render('app/evaluate/servicelist_dynamic.ejs',result);
    })
});

//评价 -- 2.1 动态获取不同类别服务列表
router.get('/evaluate/servicelistbytype', function(req, res, next) {

    evaluateService.getEvaluateServiceListByType(req, res, function(result) {
        res.send(result);
    })
});

//评价 -- 3.服务详情
router.get('/evaluate/servicedetail', function(req, res, next) {

    evaluateService.getEvaluateDetailInfo(req, res, function(result) {
        res.render('app/evaluate/servicedetail.ejs',result);
    })
});

//评价 -- 4.提交服务评价
router.post('/evaluate/updatescore', function(req, res, next) {
    evaluateService.updateScore(req, res, function(result) {
        res.send(result);
    })
});

//重点推荐
//重点推荐-重点推荐首页
router.get('/recommend/recommendindex', function(req, res, next) {
    recommendService.getRecommendtList(req, res, function(result) {
        res.render('app/recommend/recommendindex.ejs',result);
    })
});

//重点推荐-新建重点推荐
router.get('/recommend/recommendadd', function(req, res, next) {
    recommendService.getSeller(req, res, function(result) {
        res.render('app/recommend/recommendadd.ejs',result);
    })
});

//重点推荐-查看重点推荐
router.get('/recommend/recommenddetail', function(req, res, next) {
    recommendService.getRecommendDetial(req, res, function(result) {
        res.render('app/recommend/recommenddetail.ejs',result);
    })
});

//重点推荐-删除重点推荐
router.post('/recommend/recommenddelete', function(req, res, next) {
    recommendService.deleteRecommend(req, res, function(result) {
        res.send(result);
    })
});

//重点推荐-保存重点推荐
router.post('/recommend/recommendsave', function(req, res, next) {
    recommendService.createRecommend(req, res, function(result) {
        res.send(result);
    })
});

//重点推荐-更新重点推荐
router.post('/recommend/recommendupdate', function(req, res, next) {
    recommendService.updateRecommend(req, res, function(result) {
        res.send(result);
    })
});
//搜索
//搜索-关键字
router.post('/search/keysearch', function(req, res, next) {
    searchService.keysearch(req, res, function(result) {
        res.send(result);
    })
});
//搜索-指定字段
router.get('/search/searchList', function(req, res, next) {
    res.render('app/search/searchList.ejs',{type:req.query.type,key:req.query.key});
}).post('/search/searchList', function(req, res, next) {
    searchService.searchList(req, res, function(result) {
        res.send(result);
    })
});

//个股推荐
//个股推荐-个股推荐首页
router.get('/stockrecommend/stockrecommendindex', function(req, res, next) {
    //stockrecommend.getStockRecommendList(req, res, function(result) {
        res.render('app/stockrecommend/stockrecommendindex.ejs',null);
    //})
});

//个股推荐-新建个股推荐
router.get('/stockrecommend/edit', function(req, res, next) {
    stockrecommend.initStockRecommend(req, res, function(result) {
        res.render('app/stockrecommend/stockrecommendedit.ejs',result);
    })
}).post('/stockrecommend/save', function(req, res, next) {
    stockrecommend.createOrUpdateStockRecommend(req, res, function (result) {
        res.redirect('/smtool_project/wxapp/stockrecommend/stockrecommendindex');
    });
});

//个股推荐-查看个股推荐
router.get('/stockrecommend/stockrecommenddetail', function(req, res, next) {
    stockrecommend.getStockRecommendInfo(req, res, function(result) {
        if(req.query.page == 'search')
            result.page = 'search';
        res.render('app/stockrecommend/stockrecommenddetail.ejs',result);
    })
});

//个股推荐-删除个股推荐
router.post('/stockrecommend/stockrecommenddelete', function(req, res, next) {
    stockrecommend.delteStockRecommendList(req, res, function(result) {
        res.send(result);
    })
});


//其他服务
//其他服务-其他服务首页
router.get('/other/otherindex', function(req, res, next) {
    otherService.getOtherServicetList(req, res, function(result) {
        res.render('app/other/otherindex.ejs',result);
    })

});

//其他服务-新建其他服务
router.get('/other/otheradd', function(req, res, next) {
    otherService.getSeller(req, res, function(result) {
        res.render('app/other/otheradd.ejs',result);
    })
});

//其他服务-查看其他服务
router.get('/other/otherdetail', function(req, res, next) {
    otherService.getOtherServiceDetial(req, res, function(result) {
        res.render('app/other/otherdetail.ejs',result);
    })
});

//其他服务-删除其他服务
router.post('/other/otherdelete', function(req, res, next) {
    otherService.deleteOtherService(req, res, function(result) {
        res.send(result);
    })
});

//其他服务-保存其他服务
router.post('/other/othersave', function(req, res, next) {
    otherService.createOtherService(req, res, function(result) {
        res.send(result);
    })
});

//其他服务-更新其他服务
router.post('/other/otherupdate', function(req, res, next) {
    otherService.updateOtherService(req, res, function(result) {
        res.send(result);
    })
});

//知识中心-首页
router.get('/knowledge/index', function(req, res, next) {
    // req.params.type = 'public';
    // knowledgeCenter.getList(req, res, function(result) {
        res.render('app/knowledge/index.ejs',{fileType:req.query.fileType||''});
    // });

});

//知识中心-获取数据
router.get('/knowledge/getList', function(req, res, next) {
    req.params.type = 'public';
    knowledgeCenter.getList(req, res, function(result) {
        res.send(result);
    });
});
//知识中心-新增
router.get('/knowledge/add', function(req, res, next) {
   res.render('app/knowledge/add.ejs');
}).post('/knowledge/add', function(req, res, next) {
    knowledgeCenter.createItem(req, res,function (err) {
      if (err){
          console.log(err);
          res.send(err);
          //res.redirect('back');
      }else{
          res.redirect('index');
      }
    });
});

//知识中心-详情
router.get('/knowledge/detail/:rowId', function(req, res, next) {
    knowledgeCenter.getDetail(req, res, function(err,result) {
        if (err){
            res.redirect('back');
        }else{
            result.fileType = req.query.fileType;
            res.render('app/knowledge/detail.ejs',result);
        }
    });
});

//知识中心-管理
router.get('/knowledge/manage', function(req, res, next) {
    req.params.type = 'personal';
    knowledgeCenter.getList(req, res, function(result) {
        res.render('app/knowledge/manage.ejs',result);
    });
});

//按名称获取券商列表
router.get('/seller/getListByName', function(req, res, next) {
        seller.getListByName(req, res, function(result) {
        res.send(result);
    })
});

//知识中心-文档删除
router.post('/knowledge/delete', function(req, res, next) {
    knowledgeCenter.deleteByIds(req, res, function() {
        res.redirect('manage');
    });
});

//个人设置-修改当前密码
router.get('/myinfo/getmyuserinfo', function(req, res, next) {
    userService.getMyUserInfo(req, res, function(result) {
        res.render('app/myinfo/myinforetpwd.ejs',result);
    })
});

router.post('/myinfo/pswrest', function(req, res, next) {
    userService.resetPwd(req, res, function(result) {
        res.send(result);
    })
});

//登录页面
router.get('/login', function(req, res, next) {
    res.render('app/login/login_index.ejs',{'session':req.session});
});


//出错页面
router.get('/error', function(req, res, next) {
    res.render('app/errorPage.ejs');
});

module.exports = router;
